/*
 *
 * @Date: 2022-06-15 20:44:15
 * @LastEditTime: 2022-06-15 20:48:21
 * @LastEditors:
 */
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {ApiPath} from "../../config/api-path";
import * as dayjs from "dayjs";
import {Campus} from "../../enum/campus";
import {PostDetail} from "../../model/post-detail";
import {HttpService} from "../../service/http.service";

@Component({
  selector: 'app-detail',
  templateUrl: './detail-page.component.html',
  styleUrls: ['./detail-page.component.scss'],
})
export class DetailPage implements OnInit {
  private postId: number;
  postDetail: PostDetail = {
    postId: 0,
    userId: 0,
    userName: "",
    postType: "",
    title: "",
    keyWord: "",
    campus: "",
    foodDescription: "",
    outAddress: "",
    inAddress: "",
    content: "",
    pictureUrl: "",
    createTime: "",
    appointedTime: "",
    agreeNum: "",
    disagreeNum: "",
    del: "",
  };

  constructor(
    private HttpSrv: HttpService,
    private router: Router,
    private activatedRoute: ActivatedRoute
  ) {
  }

  ngOnInit() {
    this.initi();
  }

  initi() {
    this.activatedRoute.params.subscribe(params => {
      this.postId = params.id;
      console.debug(params);
    });
    this.HttpSrv.httpGet<PostDetail>(ApiPath.request.forum.postDetail, {postId: this.postId})
      .subscribe(res => {
        if (res.code === 0) {
          Object.assign(this.postDetail, res.data);
          this.postDetail.pictureUrl = ApiPath.IMAGE_SERVER_PATH + "headImg" + res.data.userId + ".jpg";
          this.postDetail.appointedTime = dayjs(res.data.appointedTime).format('MM-DD HH:mm');
          this.postDetail.campus = Campus[res.data.campus];
          this.postDetail.createTime = dayjs(res.data.createTime).format('MM-DD HH:mm');
          this.postDetail.postType = res.data.postType === "h" ? "帮助" : "求助";
        }
        console.log(this.postDetail)
      });
  }

}
